package com.du.demo.controller;


import com.du.demo.entity.Employee;
import com.du.demo.exception.CustomException;
import com.du.demo.service.EmployeeService;
import com.du.demo.utils.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
public class Hello {

@Autowired
    EmployeeService employeeService;

//    @GetMapping("/hello")
//    public BaseResult hello(){
//        isInt(30,"张三");
//        return BaseResult.success("我是后端服务数据");
//    }
    @GetMapping("/age")
    public BaseResult getAge (){
        throw new CustomException("502","服务器有问题");
    }


    @GetMapping("/map")
    public BaseResult getInfo(){
        HashMap<String, String> map = new HashMap<>();
        map.put("userName","张三");
        map.put("passWord","12345");
        map.put("age","20");
        return BaseResult.success(map);
    }
 @GetMapping("/getAll")
    public BaseResult getAll(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize){

        PageInfo<Employee> pageInfo=employeeService.setAll(pageNum,pageSize);
        return BaseResult.success(pageInfo);
 }


    @GetMapping("/selectById/{id}")
    public BaseResult selectById(@PathVariable("id") Integer id){
        return BaseResult.success(employeeService.setById(id));
    }

//    @DeleteMapping
  //  @PostMapping
}
